﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PMS.BusinessFacade;
using PMS.EntityManage;
using PMS.Common;
using PMS.EntityQuery;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using BusinessFacade;
using EntityManage;

public partial class Modules_Personal_PerfApplyApprovalView : System.Web.UI.Page
{
    IPerf_Personal_ApprovalHandler approvalHandler = new Perf_Personal_ApprovalManage();
    ISys_UserHandler userHandler = new Sys_UserManage();
    IPerf_Personal_EvaluateHandler evalHandler = new Perf_Personal_EvaluateManage();
    IPerf_Personal_EvaluateDtlHandler evalDtlHandler = new Perf_Personal_EvaluateDtlManage();
    IPerf_Personal_TargetHandler targetHandler = new Perf_Personal_TargetManage();
    IPerf_Personal_TargetTypeHandler ttHandler = new Perf_Personal_TargetTypeManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dataBind();
        }
    }

    private void dataBind()
    {
        if (Request["ID"] != null && Request["ID"] != string.Empty)
        {
            int ID = 0;
            int.TryParse(Request["ID"], out ID);

            if (ID != 0)
            {
                try
                {
                    Perf_Personal_ApprovalQuery approvalQuery = approvalHandler.GetPerf_Personal_ApprovalQuery(ID);
                    Sys_UserQuery userQuery = userHandler.GetSys_UserQuery(approvalQuery.Target_User_ID);
                    lblTargetUser.Text = userQuery.Name;
                    lblAppTitle.Text = approvalQuery.Title;
                    lblPerfDate.Text = approvalQuery.Perf_Date.ToString();
                    lblScore.Text = approvalQuery.Score.ToString();
                    lblTaskScore.Text = approvalQuery.Task_Score.ToString();
                    lblPlusScore.Text = approvalQuery.Plus_Score.ToString();
                    lblPlusReason.Text = approvalQuery.Plus_Reason;
                    lblNoticeLen.Text = approvalQuery.Notice_Len.ToString();
                    lblAppealLen.Text = approvalQuery.Appeal_Len.ToString();
                    lblStatus.Text = Enums.GetPersonalApprovalStatus((Enums.PersonalApprovalStatus)approvalQuery.Status);
                    lblRemark.Text = approvalQuery.Remark;

                    Perf_Personal_EvaluateQuery[] evalList = evalHandler.GetPerf_Personal_EvaluateQueryList(" ID = @ID", new SqlParameter[]{ new SqlParameter("@ID", approvalQuery.EvaluateIDs)});
                    StringBuilder evaIds = new StringBuilder();
                    evaIds.Append("0,");
                    if (evalList != null && evalList.Length > 0)
                    {
                        foreach (Perf_Personal_EvaluateQuery evaQuery in evalList)
                        {
                            evaIds.Append(evaQuery.ID.ToString());
                            evaIds.Append(",");
                        }
                    }
                    evaIds = evaIds.Remove(evaIds.Length - 1, 1);
                    DataTable dt = evalDtlHandler.GetPerf_Personal_EvaluateDtlList(" Evaluate_ID in(" + evaIds.ToString() + ")", new SqlParameter[] { }, " Evaluate_ID asc");
                    gvEvalList.DataSource = dt;
                    gvEvalList.DataBind();
                }
                catch
                {
                    Jscript.Alert("操作失败!", this.Page);
                }
            }
        }
    }


    protected void gvEvalList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowIndex > -1)
            {
                Perf_Personal_EvaluateQuery evaQuery = evalHandler.GetPerf_Personal_EvaluateQuery(int.Parse(e.Row.Cells[0].Text));
                if (evaQuery != null)
                {
                    Sys_UserQuery userQuery = userHandler.GetSys_UserQuery(evaQuery.User_ID);
                    if (userQuery != null)
                    {
                        e.Row.Cells[0].Text = userQuery.Name;
                    }
                    e.Row.Cells[1].Text = evaQuery.Create_Time.ToString("yyyy-mm-dd");
                }

                Perf_Personal_TargetQuery targetQuery = targetHandler.GetPerf_Personal_TargetQuery(int.Parse(e.Row.Cells[2].Text));
                if (targetQuery != null)
                {
                    e.Row.Cells[2].Text = targetQuery.Name;
                    e.Row.Cells[4].Text = targetQuery.Score.ToString();

                    Perf_Personal_TargetTypeQuery ttQuery = ttHandler.GetPerf_Personal_TargetTypeQuery(targetQuery.TargetType_ID);
                    if (ttQuery != null)
                    {
                        e.Row.Cells[3].Text = ttQuery.Name;
                    }
                }
            }
        }
    }
}
